// Define AppState structure for axum
use std::sync::Arc;

use tokio::sync::{mpsc, oneshot};

use crate::types::channel::{Request, Response};

pub struct State {
    pub tx_to_rauth_grpc_channel: Arc<mpsc::Sender<(Request, oneshot::Sender<Response>)>>,
    pub tx_to_iblog_grpc_channel: Arc<mpsc::Sender<(Request, oneshot::Sender<Response>)>>,
    pub tx_to_redis_channel: Arc<mpsc::Sender<(Request, oneshot::Sender<Response>)>>,
}

impl State {
    pub fn new(
        tx_to_rauth_grpc_channel: mpsc::Sender<(Request, oneshot::Sender<Response>)>,
        tx_to_iblog_grpc_channel: mpsc::Sender<(Request, oneshot::Sender<Response>)>,
        tx_to_redis_channel: mpsc::Sender<(Request, oneshot::Sender<Response>)>,
    ) -> Self {
        State {
            tx_to_rauth_grpc_channel: Arc::new(tx_to_rauth_grpc_channel),
            tx_to_iblog_grpc_channel: Arc::new(tx_to_iblog_grpc_channel),
            tx_to_redis_channel: Arc::new(tx_to_redis_channel),
        }
    }
}

pub type SharedState = Arc<State>;
